package com.guyaogg.gulimall.product.web;

import com.guyaogg.gulimall.product.service.SkuInfoService;
import com.guyaogg.gulimall.product.vo.SkuItemVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.concurrent.ExecutionException;

/**
 * @author 顾遥
 */
@Slf4j
@Controller
public class ItemController {

    private final SkuInfoService skuInfoService;

    public ItemController(SkuInfoService skuInfoService) {
        this.skuInfoService = skuInfoService;
    }

    /**
     * 展示当前 sku 的详情
     *
     * @param skuId sku 的 id
     * @return
     */
    @GetMapping("/{skuId}.html")
    public String skuItem(@PathVariable("skuId") Long skuId, Model model) throws ExecutionException, InterruptedException {
        log.debug("准备查询 {} 的详情", skuId);
       SkuItemVO skuItem =  skuInfoService.item(skuId);
       model.addAttribute("result", skuItem);

        return "item";
    }
}
